document.onkeydown = function (event) {
    var target, code, tag;
    if (!event) {
        event = window.event; //针对ie浏览器
        target = event.srcElement;
        code = event.keyCode;
        if (code == 13) {
            tag = target.tagName;
            if (tag == "TEXTAREA") {
                return true;
            } else {
                return false;
            }
        }
    } else {
        target = event.target; //针对遵循w3c标准的浏览器，如Firefox
        code = event.keyCode;
        if (code == 13) {
            tag = target.tagName;
            if (tag == "INPUT") {
                return false;
            } else {
                return true;
            }
        }
    }
};

//------- Start 判断输入的是否是证书和小数还有0

function CupperCase(obj) {//用户只能输入正负数与小数

    var inum = 6;
    var newValue;

    if (inum == 1) {

        if (isNaN(obj.value) && !/^-$/.test(obj.value)) {
            obj.value = "";
        }
        if (!/^[+-]?\d*\.{0,1}\d{0,1}$/.test(obj.value)) {
            obj.value = obj.value.replace(/\.\d{1,}$/, obj.value.substr(obj.value.indexOf('.'), inum));
            obj.value = newValue.replace('.', '');
        }
    } else {

        if (isNaN(obj.value) && !/^-$/.test(obj.value)) {
            obj.value = "";
        }
        if (!/^[+-]?\d*\.{0,1}\d{0,1}$/.test(obj.value)) {
            obj.value = obj.value.replace(/\.\d{1,}$/, obj.value.substr(obj.value.indexOf('.'), inum));
        }
    }
}


function Wonkeyup(obj) {//用户只能输入正负数与小数
    var inum = 4;

    // if(inum.length==5){inum==4;}else{inum=3;}

    if (isNaN(obj.value) && !/^-$/.test(obj.value)) {
        obj.value = "";
    }
    if (!/^[+-]?\d*\.{0,1}\d{0,1}$/.test(obj.value)) {
        obj.value = obj.value.replace(/\.\d{1,}$/, obj.value.substr(obj.value.indexOf('.'), inum));
    }
}

//------- End 判断输入的是否是证书和小数还有0


function Button2_onclick() {
    var mymessage = confirm("你确定需要保存吗？或者在检查一遍？");

    if (mymessage == true) {
        return true;
    } else {
        return false;
    }

}


function ResoultFloat(arg1, arg2) {
    var t1 = 0, t2 = 0, r1, r2;
    try {
        t1 = arg1.toString().split(".")[1].length
    } catch (e) {
    }
    try {
        t2 = arg2.toString().split(".")[1].length
    } catch (e) {
    }
    with (Math) {
        r1 = Number(arg1.toString().replace(".", ""));
        r2 = Number(arg2.toString().replace(".", ""));
        return (r1 / r2) * pow(10, t2 - t1);
    }

}


function _SetDigitalInput(oInput) {

    if (oInput == 2 || oInput == 8 || oInput == 14) {

        oInput = 14;

    }
    if (oInput == 20 || oInput == 26 || oInput == 32) {

        oInput = 32;

    }
    if (oInput == 38 || oInput == 44 || oInput == 50) {

        oInput = 50;

    }
    if (oInput == 56 || oInput == 62 || oInput == 68) {

        oInput = 68;

    }

    var f = oInput - 6;
    var j = oInput - 12;

    var f_01 = Number(document.getElementById("B" + f).value == "" ? 0 : document.getElementById("B" + f).value);
    var f_02 = Number(document.getElementById("B" + j).value == "" ? 0 : document.getElementById("B" + j).value);

    var f_03 = Number(document.getElementById("B" + oInput).value == "" ? 0 : document.getElementById("B" + oInput).value);

    var f_value = f_01 + f_02 + f_03;


    var Avg_x = ResoultFloat(f_value * 10000, 3) / 10000;


    var k = oInput + 1;
    var i = oInput - 5;
    var r = oInput - 11;

    document.getElementById("B" + k).value = document.getElementById("B" + i).value =
        document.getElementById("B" + r).value = changeTwoDecimal_y(Avg_x, 3);


    if (parseFloat(document.getElementById("BLPH_FW_01").value.replace("%", "").replace("mg/g", "")) >= 5) {

        strdn = parseFloat(document.getElementById("BLPH_FW_01").value.replace("%", "").replace("mg/g", "")) / 10;

    } else {

        strdn = parseFloat(document.getElementById("BLPH_FW_01").value.replace("%", ""));

    }


    document.getElementById("B58").value = document.getElementById("B64").value =
        document.getElementById("B70").value = changeTwoDecimal_y(((document.getElementById("B69").value == "" ? 0 : document.getElementById("B69").value - strdn) / strdn * 100), 1);

    document.getElementById("B40").value = document.getElementById("B46").value =
        document.getElementById("B52").value = changeTwoDecimal_y(((document.getElementById("B51").value == "" ? 0 : document.getElementById("B51").value - strdn) / strdn * 100), 1);

    document.getElementById("B22").value = document.getElementById("B28").value =
        document.getElementById("B34").value = changeTwoDecimal_y(((document.getElementById("B33").value == "" ? 0 : document.getElementById("B33").value - strdn) / strdn * 100), 1);

    document.getElementById("B4").value = document.getElementById("B10").value =
        document.getElementById("B16").value = changeTwoDecimal_y(((document.getElementById("B15").value == "" ? 0 : document.getElementById("B15").value - strdn) / strdn * 100), 1);


}


function SetDigitalInputC(oInput) {

    // var strdn = parseFloat(document.getElementById("BLPH_FW_01").value.replace("%", ""));
    if (parseFloat(document.getElementById("BLPH_FW_01").value.replace("%", "").replace("mg/g", "")) >= 5) {

        strdn = parseFloat(document.getElementById("BLPH_FW_01").value.replace("%", "").replace("mg/g", "")) / 10;

    } else {

        strdn = parseFloat(document.getElementById("BLPH_FW_01").value.replace("%", ""));

    }

    var H_1 = parseFloat(document.getElementById("C2").value == "" ? 0 : document.getElementById("C2").value);
    var H_2 = parseFloat(document.getElementById("C8").value == "" ? 0 : document.getElementById("C8").value);
    var H_3 = parseFloat(document.getElementById("C14").value == "" ? 0 : document.getElementById("C14").value);
    var H_4 = parseFloat(document.getElementById("C20").value == "" ? 0 : document.getElementById("C20").value);
    var H_5 = parseFloat(document.getElementById("C26").value == "" ? 0 : document.getElementById("C26").value);
    var H_6 = parseFloat(document.getElementById("C32").value == "" ? 0 : document.getElementById("C32").value);

    var f_d = H_1 + H_2 + H_3 + H_4 + H_5 + H_6;
    var Avg_x = ResoultFloat(f_d, 6);

    document.getElementById("C3").value = document.getElementById("C9").value
        = document.getElementById("C15").value
        = document.getElementById("C21").value
        = document.getElementById("C27").value
        = document.getElementById("C33").value = changeTwoDecimal_y(Avg_x, 3);


    var J_1 = (H_1 - Avg_x) * (H_1 - Avg_x);
    var J_2 = (H_2 - Avg_x) * (H_2 - Avg_x);
    var J_3 = (H_3 - Avg_x) * (H_3 - Avg_x);
    var J_4 = (H_4 - Avg_x) * (H_4 - Avg_x);
    var J_5 = (H_5 - Avg_x) * (H_5 - Avg_x);
    var J_6 = (H_6 - Avg_x) * (H_6 - Avg_x);

    var s_7 = (J_1 + J_2 + J_3 + J_4 + J_5 + J_6) / 5;

    var f_f = Math.pow(parseFloat(s_7), 0.5);

    var f_T = f_f / strdn * 100;

    document.getElementById("C4").value = document.getElementById("C10").value
        = document.getElementById("C16").value
        = document.getElementById("C22").value
        = document.getElementById("C28").value
        = document.getElementById("C34").value = changeTwoDecimal_y(f_T, 1);


}


function changeTwoDecimal_f(x) {
    var f_x = parseFloat(x);
    if (isNaN(f_x)) {
        alert('function:changeTwoDecimal->parameter error');
        return false;
    }
    f_x = Math.round(f_x * 10000) / 10000;
    var s_x = f_x.toString();
    var pos_decimal = s_x.indexOf('.');
    if (pos_decimal < 0) {
        pos_decimal = s_x.length;
        s_x += '.';
    }
    while (s_x.length <= pos_decimal + 3) {
        s_x += '0';
    }
    return s_x;
}

function changeTwoDecimal_y(s_x, inum) {

    var s_x_old = s_x;

    if (String(s_x).length >= 10) {

        s_x = s_x.toFixed(inum + 1);

    }

    if (isNaN(s_x)) {
        alert('function:changeTwoDecimal->parameter error');
        return false;
    }

    // 转成字符型

    s_x = s_x.toString();


    //确定是否有小数点

    var pdecimal = s_x.indexOf('.');


    if (pdecimal < 0) {
        pdecimal = s_x.length;
        s_x += '.';
    }

    while (s_x.length < parseInt(parseInt(pdecimal) + parseInt(inum + 2))) {
        s_x += '0';
    }


    var inums = inum + s_x.indexOf('.');


    var iReturnValue = "";


    if (s_x.length > (parseInt(inums) + 2)) {
        s_x = s_x.substring(0, (parseInt(inums) + 2));
    }


    var s_x_l = parseInt(s_x.substring(s_x.length - 1, s_x.length));

    var s_x_2 = parseInt(s_x.substring(s_x.length - 2, s_x.length - 1));


    var kj = parseFloat(Math.pow(10, -inum).toFixed(inum));


    if (s_x_l == 5) {


        if (Math.abs(parseFloat(s_x_old)) > Math.abs(parseFloat(s_x))) {


            iReturnValue = parseFloat(s_x) > 0 ? String((Math.round(parseFloat(s_x.substring(0, parseInt(inums + 1))) * 1000000) + Math.round(parseFloat(kj) * 1000000)) / 1000000) : String((Math.round(parseFloat(s_x.substring(0, parseInt(inums + 1))) * 1000000) - Math.round(parseFloat(kj) * 1000000)) / 1000000);


        } else {

            if (s_x_2 == 0 || s_x_2 % 2 == 0) {

                iReturnValue = (s_x.substring(0, parseInt(inums + 1)));


            } else if (s_x_2 != 0 && s_x_2 % 2 != 0) {

                iReturnValue = parseFloat(s_x) > 0 ? String((Math.round(parseFloat(s_x.substring(0, parseInt(inums + 1))) * 1000000) + Math.round(parseFloat(kj) * 1000000)) / 1000000) : String((Math.round(parseFloat(s_x.substring(0, parseInt(inums + 1))) * 1000000) - Math.round(parseFloat(kj) * 1000000)) / 1000000);

            }
        }
    } else {


        if (s_x_l >= 6) {


            iReturnValue = parseFloat(s_x) > 0 ? String((Math.round(parseFloat(s_x.substring(0, parseInt(inums + 1))) * 1000000) + Math.round(parseFloat(kj) * 1000000)) / 1000000) : String((Math.round(parseFloat(s_x.substring(0, parseInt(inums + 1))) * 1000000) - Math.round(parseFloat(kj) * 1000000)) / 1000000);


        } else {

            iReturnValue = (s_x.substring(0, parseInt(inums + 1)));


        }

    }

    return iReturnValue;
}


//

var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}

function __doPostBack(eventTarget, eventArgument
) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}

//]]>

